package fr.uvsq.isty.bdh.hchess.gui.menu;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;


/**
 * Loading page when we start a game
 * @author Nathan
 *
 */
public class LoadingMenu extends JPanel{
	
	/**
	 * Background image.
	 */
	private Image bg;
	
	/**
	 * Label containing the animated picture
	 */
	private JLabel load;
	
	
	/**
	 * The constructor, just loading two pictures.
	 */
	public LoadingMenu()
	{		
		//Background
		try {
			bg = ImageIO.read(getClass().getClassLoader()
                                .getResource("menu/menu.jpg"));
		} catch (IOException e1) {			
			e1.printStackTrace();
		}	

		
		//We put the picture in a label to make it animated
		ImageIcon test = new ImageIcon(getClass().getClassLoader()
                                .getResource("menu/loading.gif"), "");
		load = new JLabel("", test, JLabel.CENTER);		
		
		load.setAlignmentX(Component.CENTER_ALIGNMENT);
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));	
		this.add(Box.createVerticalGlue()); 
		this.add(load);
		this.add(Box.createVerticalGlue()); 
		
	}
	
	 @Override
	 /**
	  * Printing the two pictures.
	  */
	 public void paintComponent(Graphics g){
		g.drawImage(bg, 0, 0, this.getWidth(), this.getHeight(), this);

	 }

}
